package src.leetcode.hot.mid_0006;

public class convert {
    public static void main(String[] args) {
        System.out.println(new Solution().convert("A", 1));
    }
}


class Solution {
    public String convert(String s, int numRows) {
        StringBuffer sb = new StringBuffer();
        int n = s.length();
        for (int i = 1; i <= numRows; i++) {
            int j = i - 1;
            while(j < n) {
                sb.append(s.charAt(j));
                if(i != numRows) j += 2 * (numRows - i);
                else j += 2 * (i - 1);

                if(j >= n) break;

                sb.append(s.charAt(j));
                if(i != 1) j += 2 * (i - 1);
                else j += 2 * (numRows - i);
            }
        }

        return sb.toString();
    }
}